// 某个模块的数据请求（增删改查！）

import $axios from "@/common/http";  // 封装的axios
import axios from "axios"   // 原生的axios
import { Message } from "element-ui"  // 提示框


export async function getMenu(id){
    // 读列表（树形、不是树形）   读某一个
    let res;
    if(id){
        res = await $axios.get("/menuinfo", { params:{id} });
    }else{
        res = await $axios.get("/menulist", { params: { istree: 1  } });  // 获取属性结构菜单！
    }
    return res.list;
}

export async function addMenu(data) {
    let res = await $axios.post("/menuadd",data);
    Message.success(res.msg)
    return true;
}

export async function editMenu(data) {
    let res = await $axios.post("/menuedit", data);
    Message.success(res.msg)
    return true;
}

export async function delMenu(id) {
    if(!id){
        Message.warning("请传入删除id");
        return;
    }
    let res = await $axios.post("/menudelete",{id})
    if(res){
        Message.success(res.msg)
        return res.list;
    }
}